/*
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 */
function onDeletePage(url, pageId, resp) {
	var isOK = -1;
	
	if(!confirm('Are you sure you want to delete the page with Id:' + pageId)) {
		return false;
	}
	
	new Ajax.Request(url, {
	  method: 'post',
	  asynchronous: false,
	  parameters:'act=delpage&id=' + pageId,
	  onSuccess: function(transport) {
			var response = transport.responseText.trim();

			obj = response.evalJSON();

    		if(obj == null) {
    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
		
    		$(resp).update(obj.message);
		}
	});

	$(resp).style.display = 'inherit';
	Fat.fade_element(resp, null, 1500, null, null);

	if(isOK == 0) {
		rowID = 'page-' + pageId;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
	}				
}

function saveAndContinueEditing(frmID, resp) {
	var newid = -1;
	var linkpage = "";
	$(frmID).request( {
			asynchronous: true,
			parameters: $(frmID).serialize(true) + '&ajax=1',
	  		onComplete: function(transport) { 
			  	var response = transport.responseText || "";
		    	//alert(response);
			  	
		    	$(resp).innerHTML = '';
		    	
		    	if(response != "") {
		    		obj = response.evalJSON();
		    		
		    		if(obj == null || obj.message == '') {
		    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
		    		}
		    		
			    	if(resp != null)
				    	$(resp).innerHTML = obj.message;
				    	
				    newid = obj.code;
				    linkpage = obj.linkpage;
		    	}
	  		}
		});

	
    
	//$(resp).show();
	$(resp).style.display = 'block';

	Fat.fade_element(resp, null, 1500, null, null);
	//document.location=linkpage;
	//revent submit page
	return false;
}

function onPageSubmit(frmID, resp, type, editor) {
	if($F('page_name') == '') {
		alert('Please Typing Page Title.');
		return false;
	}
	
	/*if($F(type) == 'ajax') {
		//$(editor).value = tinyMCE.getContent(editor);
		//saveAndContinueEditing(frmID, resp);
		return false;
	}*/

	return true;
}